<template>
  <div ref="myCharts" class="echarts"></div>
</template>
<script>
import echarts from 'echarts'
export default {
  data() {
    return {}
  },
  props: {
    option: {
      type: Object,
      default: () => {}
    }
  },
  watch: {
    option: {
      handler() {
        this.initCharts()
      },
      deep: true
    }
  },
  mounted() {
    this.initCharts()
  },
  methods: {
    initCharts() {
      let myCharts = echarts.init(this.$refs.myCharts)
      myCharts.showLoading()
      myCharts.setOption(this.option)
      setTimeout(() => {
        myCharts.hideLoading()
      }, 1000)
    }
  }
}
</script>
<style lang="scss" scoped>
.echarts {
  width: 100%;
  height: 600px;
}
</style>
